/**
 * 
 */
package optimization.naturalOptimization.evolutionaryAlgorithm.evolutionStrategy.cma;

import java.util.Comparator;

/**
 * @author Kevin
 * 
 */
public class IntDouble implements Comparator<IntDouble> {
	private int i; // unique integer value, useful after sorting
	private double val; // double value

	/**
	 * @param d
	 * @param i
	 */
	public IntDouble(double d, int i) {
		this.val = d;
		this.i = i;
	}

	/**
	 * @param d
	 */
	public IntDouble(double d) {
		this.val = d;
	}

	/**
     * 
     */
	public IntDouble() {
	}

	/**
	 * @param o1
	 * @param o2
	 * @return comparison
	 */
	public int compare(IntDouble o1, IntDouble o2) {
		if (o1.val < o2.val)
			return -1;
		if (o1.val > o2.val)
			return 1;
		if (o1.i < o2.i)
			return -1;
		if (o1.i > o2.i)
			return 1;
		return 0;
	}

	/**
	 * @param o1
	 * @param o2
	 * @return equality
	 */
	public boolean equals(IntDouble o1, IntDouble o2) {
		if (o1.compare(o1, o2) == 0) // && o1.hashCode() == o2.hashCode()
			return true;
		return false;
	}

	/**
	 * Returns the index of the {@link IntDouble}
	 * 
	 * @return index
	 */
	public int getIndex() {
		return i;
	}

	/**
	 * Returns the value of the {@link IntDouble}
	 * 
	 * @return value
	 */
	public double getValue() {
		return val;
	}
	
	/**
	 * 
	 * @param i
	 */
	public void setIndex(int i){
		this.i=i;
	}
	
	/**
	 * 
	 * @param value
	 */
	public void setValue(double value){
		this.val=value;
	}
	
} // IntDouble
